#include "stm32f10x.h"
#include "usart.h"
#include "stdio.h"
#include "i2c.h"
#include "tim.h"
#include "lcd.h"
#include "key.h"
#include "led.h"

u32 TimingDelay = 0;
u8 set_channel = 0;
u8 set_n[2] = {2,2};
u16 fre1 = 1000;
u16 fre2 =  3000;
extern u8 lcd_state;
//Main Body
int main(void)
{
	char text[20];
	SysTick_Config(SystemCoreClock/1000);
	USART_CofigInit();
	STM3210B_LCD_Init();
	LCD_SetTextColor(White);
	LCD_SetBackColor(Blue2);
	LCD_Clear(Blue2);
	led_init();
	capture();
	tim_init();
	key_init();
	i2c_init();
	NVIC_PriorityGroupConfig( NVIC_PriorityGroup_2);
	set_n[0] = read_data(1);
	set_n[1] = read_data(3);
	
	while(1)
	{
		state_get();
		if(fre1>50000)
			GPIO_ResetBits(GPIOA,GPIO_Pin_6);
		if(fre2>50000)
			GPIO_ResetBits(GPIOA,GPIO_Pin_7);
		if(fre1>0)
			led_ctrl(led1,0);
		else
			led_ctrl(led1,1);
		if(fre2>0)
			led_ctrl(led2,0);
		else
			led_ctrl(led2,1);
		sprintf(text,"Channel(1):%dHz   ",fre1);
		LCD_DisplayStringLine(Line2,text);
		sprintf(text,"N(1):%d   ",set_n[0]);
		LCD_DisplayStringLine(Line3,text);
		sprintf(text,"Channel(2):%dHz   ",fre2);
		LCD_DisplayStringLine(Line4,text);
		sprintf(text,"N(2):%d   ",set_n[1]);
		LCD_DisplayStringLine(Line5,text);
		sprintf(text,"           %d",set_channel+1);
		LCD_DisplayStringLine(Line7,text);
	}
}

//

